^ What's the point?
^ Requirements
^ Installation
^ Usage
^ HResult error codes
^ BASS COM Management
^ Licenses
^ Useful information

Download :: Top
BASS Encoder Library

BASS Encoder Library is a COM/DLL MP3, Opus, FLAC, Ogg Vorbis, AAC and WAV encoder component that uses BASS for encoding audio files, for use in Win32 and Win64 (Windows XP/Vista/7/8/10) software.
Encodes audio file formats supported by BASS: WAV/RF64, AIFF, AIFC, MP3, MP2, MP1, Ogg Vorbis (and formats supported by BASS plugins), music module formats supported by BASS (MOD, MTM, S3M, XM, IT, MO3), and OS supported formats like AAC/MP4, Flac, etc. to MP3, Opus, FLAC, Ogg Vorbis and WAV format or use a command line encoder.

Features:
  • Encode various audio file formats into MP3, Opus, FLAC, Ogg Vorbis, AAC and WAV format
  • Encode the files with an external command line encoder tool
  • COM class usable by developer environments/platforms supporting COM classes like VBScript
  • Stream encoding interface for MP3 (send sample data to the component and receive the encoded MP3 data)
  • ID3v1, ID3v2, Lyrics3, APEv2, Flac, Ogg Vorbis, Opus, MP4, WAV LIST INFO, BEXT and CART and WMA tags are transferred to output file
  • Optionally specify segment to encode or use silence detection to trim leading and trailing silence
  • Normalize the volume to arbitrary amount
  • Optional lowpass and highpass filtering
  • Supports using the BASSEncoder.dll itself natively without COM, Delphi and C++ API included
  • As no external .exe is started the library is usable for Windows Store apps (except when using the external command line encoder class)

Requirements

Developer environment/platform supporting COM classes or DLLs.


Installation

Run an elevated command prompt, change dir into the folder where 'BASSEncoder.dll' is located, run the following: "regsvr32 BASSEncoder.dll". This should register the COM class. Do this for the desired Win32 and/or Win64 version.
When using the BASS method bass.dll and bass_fx.dll is needed on the search path, eg. beside your .exe, or copy the needed DLLs to \Windows\System32\ (Win64 DLLs on a 64 bit OS) and/or \Windows\SysWOW64\ (Win32 DLLs on a 64 bit OS) folder. If the OS is 32 bit then copy the needed DLLs to \Windows\System32\ (from the Win32 folder).
To use the library in VBScript, on a 64 bit OS, the VBScript process is 64 bit so the needed DLLs have to be from the Win64 folder, beside the .VBS file or in the System32 folder as written above.


Usage

After registering the DLL it can be accessed like:
    createobject("BASSEncoder.TLAMEEncodeFile");

    createobject("BASSEncoder.TBASSEncodeFileOpus");

    createobject("BASSEncoder.TBASSEncodeFileFLAC");

    createobject("BASSEncoder.TBASSEncodeFileVorbis");

    createobject("BASSEncoder.TBASSEncodeFileAAC");

    createobject("BASSEncoder.TBASSEncodeFileWAV");

    createobject("BASSEncoder.TBASSEncodeFileCommandLine");
VBScript usage example, output 320 kbps, 44 100 Hz, 2 channel CBR MP3 audio file:
    option explicit
    dim myobject
    set myobject = createobject("BASSEncoder.TLAMEEncodeFile")
    myobject.LoadBASSFormatPlugin "bass_ape.dll" 'optional, load needed BASS plugins here before calling 'EncodeFileWithBASS()'
    myobject.EncodeFileWithBASS "E:\Test.wav", "E:\Test.mp3", 320, 44100, 2, 0, 0, 0, 0, nothing
    set myobject = nothing
or using eg. Opus, and use source file's attributes:
    option explicit
    dim myobject
    set myobject = createobject("BASSEncoder.TBASSEncodeFileOpus")
    myobject.EncodeFile "E:\Test.wav", "E:\Test.mp3", '--bitrate 320', 0, 0, 0, 0, 0, nothing, 0
    set myobject = nothing
Please see the Delphi tutorials on how to use the library with Delphi.

Parameters: Specifying 0 for 'ResampleSampleRate' and/or 'Channels' means automatic, best quality, values. If the input file's attribute is larger than the allowed maximum value the maximum supported value is used, if the source file's attribute is supported by the output format the source file's attribute is used.
Note that encoding to Opus format sample data is always (resampled to) 48 000 Hz.
When using the external command line encoder class 'OutputFileName' must match the output file name in 'Parameters', the output file name must be also passed within the 'Parameters' variable that should include the full path to the encoder .exe, all the encoder parameters and the output file name as well. Note that the external encoder should be told to expect the audio data from stdin. For details about the function please see 'BASS_Encode_Start()' documentation in 'bassenc.chm' (in bassenc24.zip).
The command line encoder class has 4 methods for some additional options: UseRF64 (False by default), UseWFEXT (False by default), UseWAVHeader (True by default) and UseDither (False by default). Specify 0 for False, non-zero value for True for these methods.
  • function EncodeFileWithBASS (const FileName, OutputFileName: WideString; BitRate: Integer; ResampleSampleRate, Channels: SYSUINT; VBR: Integer; StartPosition, Length, Normalize: Double; const ProgressCallback: IProgress): HResult;
    • If 'ResampleSampleRate' is 0 then the source file's sample rate is used. Valid range is 8000 to 48000.
    • If 'Channels' is 0 then the source file's channel count is used. Valid value is 1 or 2.
    • Set 'VBR' to a non-zero value to enable VBR encoding mode.
    • 'StartPosition' and 'Length' are in seconds. Use 0 for all.
    • Set 'Normalize' to 1.0 (100%) or specify 0 (don't change).
    • 'ProgressCallback' is an interface callback for encoding progress reporting. Set to nil if you don't wish to use a progress callback.
  • function EncodeFileSilenceDetected (const FileName, OutputFileName: WideString; BitRate: Integer; ResampleSampleRate, Channels: SYSUINT; VBR: Integer; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; const ProgressCallback: IProgress): HResult; stdcall;
    • Same as EncodeFileWithBASS() with 3 different parameters:
    • 'MaxSilenceVolume' set to 1.0 for 100%, usualy value is 0.05 - 0.1.
    • 'PrependLength' and 'AppendLength' are in seconds, extend the detected segment by this amount.
Using BASSEncoder.dll natively: There are exported functions available:
  • function LAMEEncodeWAVFile(FileName, OutputFileName: PWideChar; BitRate: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function LAMEEncodeFileWithBASS(FileName, OutputFileName: PWideChar; BitRate, ResampleSampleRate, Channels, VBR: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileOpus(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileFLAC(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileOggVorbis(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileWAV(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileCommandLine(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; UseRF64, UseWFEXT, UseWAVHeader, UseDither: LongBool; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileAAC(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileWithBASSSilenceDetected(FileName, OutputFileName: PWideChar; BitRate, ResampleSampleRate, Channels, VBR: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileOpusSilenceDetected(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileFLACSilenceDetected(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileOggVorbisSilenceDetected(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileWAVSilenceDetected(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileCommandLineSilenceDetected(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; UseRF64, UseWFEXT, UseWAVHeader, UseDither: LongBool; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileAACSilenceDetected(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function LAMEEncoderGetFile: ILAMEEncodeFile; stdcall;
  • function LAMEEncoderGetStream: ILAMEEncodeStream; stdcall;
  • function BASSEncoderGetFileOpus: IBASSEncodeFile; stdcall;
  • function BASSEncoderGetFileFLAC: IBASSEncodeFile; stdcall;
  • function BASSEncoderGetFileVorbis: IBASSEncodeFile; stdcall;
  • function BASSEncoderGetFileWAV: IBASSEncodeFile; stdcall;
  • function BASSEncoderGetFileCommandLine: IBASSEncodeFile; stdcall;
  • function BASSEncoderGetFileAAC: IBASSEncodeFile; stdcall;
The first functions can be used to directly call the encoder functions.
The last functions return the interface for the 'ILAMEEncodeFile', 'ILAMEEncodeStream' and Opus/FLAC/Ogg Vorbis/AAC/WAV/Command line encoder 'IBASSEncodeFile' classes.

AAC options:
The default is type 2 CBR with the bitrate based on the sample rate and channel count.

AAC is patented and a licence is required to use it in commercial products. A licence can be obtained from Via: www.via-corp.com/licensing/aac/


HResult error codes
  • S_OK: Success.
  • S_FALSE: Unknown error occured or catastrophic failure.
  • 2: lame_enc.dll could not be loaded.
  • 3: bass.dll could not be loaded.
  • 4: bassmix.dll could not be loaded.
  • 5: bassenc_opus.dll could not be loaded.
  • 6: bassenc_flac.dll could not be loaded.
  • 7: bassenc_ogg.dll could not be loaded.
  • 8: bass_fx.dll could not be loaded.
  • 9: Input file could not be opened.
  • 10: Output file could not be created.
  • E_INVALIDARG: Parameters specified are invalid.

BASS COM Management

BASSCOMManagement.dll first must be registered before using it, please see 'Installation' section.

BASS COM Management class should be used when running the COM classes in a multi-threded environment and using Sample Display Library together with for example BASS Encoder Library.
The individual components don't know of each other's state and they are both using BASS. To overcome this issue 'BASSCOMManagement.BASSManagement' COM class should be used when starting the process to initialize BASS for all the COM classes.
There are only 2 functions: 'BASSInitialize' and 'BASSFree'. 'BASSInitialize' expects only one parameter, the audio device number, it should be '0', the COM classes need to have BASS initialized for 0, the "no sound device".
When starting the process use:
	option explicit
	dim myobject
	set myobject = createobject("BASSCOMManagement.BASSManagement")
	myobject.BASSInitialize 0
	set myobject=nothing
And just before the process exits call:
	option explicit
	dim myobject
	set myobject = createobject("BASSCOMManagement.BASSManagement")
	myobject.BASSFree
	set myobject=nothing
	
The state is stored globally per process, and is valid until unloading the 'BASSCOMManagement.dll' from the process. Also the initialization and free calls are reference counted.

A simpler solution is to never free BASS - BASS will free itself when the BASS.dll is unloaded anyway. Use 'FreeBASS(1)' to set it to free it when freeing the BASS Encoder Library class. The default state is '0'.

When not using a scripting language it's only needed to call BASS_Init() manually (with device '0') on your program startup, and BASS_Free() on program exit, directly with BASS.dll.


BASS Encoder Library in shareware and commercial software?

You can use this component in your free programs with a freeware license (non-money-making use). If you like it and use it in a shareware or commercial (or any other money making - advertising, in app. selling, etc.) product one of the licenses is needed.


Useful information


[Top]